$(() => {
    const token = GetQueryString("token");
    // 获取area_id
    let id = GetQueryString('id');

    $.ajax({
        type: "post",
        url: url,
        data: { 'method': "Goods|goods_detail", 'id': id, 'token': token },
        dataType: 'json',
        success: function(res) {
            // console.log(res);
            if (res.status == 1) {
                let html = '';
                let banner = '';
                let shop = '';
                let company = res.data.company;
                let goods = res.data.goods;
               
                // 标题名称
                $('title').html(goods.goods_name);
                $('.detailShop img').attr("src",goods.description_img);
                shop += `
                    <div class="headlineText" style="margin-bottom: .1rem;">${goods.goods_name}</div>`
                    if(goods.price_show_model == 1){
                        shop +=`<p class="redPrice">¥${goods.goods_price}</p>`;
                    }else if(goods.price_show_model == 2){
                        shop +=`<p class="redPrice"><del style="color:#666;font-size:.24rem;">¥${goods.price_before}</del>/<span style="font-size:.28rem;">¥${goods.goods_price}</span></p>`;
                    }else{
                        shop +=`<p class="redPrice">¥${goods.price_area}</p>`;
                    }
                html += `<div class="comHead">
                            <div class="comHeadLeft">
                            <img class="headImg" src="${company.company_logo == '' ? '../img/user.jpg' : company.company_logo }" alt="${company.company_name}">
                            <div class="headlineTopChild">
                                <p>${company.company_name}</p>`
                if (company.level_logo != '') {
                    html += `<img src="${company.level_logo}" class="userLevel" alt="${company.level_name}"/>`
                }
                html += `</div>
                        </div>
                        <p class="comHeadRight">进店</p>
                        </div>
                    <p class="mainDesc">主营：${company.main_business}</p>
                `;
                $('.shopDetailText').html(shop);
                $('.headWrap').html(html);

                goods.pic_list.forEach(item => {
                    banner += `
                        <div class="swiper-slide"><img data-id="${item.id}" src="${item.thumb_url == '' ? '../img/banner.png' : item.thumb_url}" data-url="${item.pic_url}" alt="${item.pic_name}" class="baimg" /></div>
                    `;
                })
                $('.swiper-wrapper').html(banner);
                // banner轮播
                new Swiper('.swiper-container', {
                    autoplay: 3000,
                    // pagination: '.swiper-pagination',
                    loop: true
                })

            } else if (res.status == 2) {
                location.href = "fox://logout";
            } else {
                alert(res.message);
            }
        }
    })

    // 联系客服
    $('.contactBtn').on('click', function() {
        let uid = $(this).attr('data-uid');
        if (uid != '') {
            if (isAndroid_ios()) {
                //安卓  
                window.android.startChat(uid);
            } else {
                //ios
                window.webkit.messageHandlers.startChat.postMessage(uid);
            }
        } else {
            alert('暂无客服信息！！！')
        }
    })

    // 分享下载链接及备案信息底部
    if ($('.downLoad').length) {
        $.ajax({
            type: "post",
            url: url,
            data: { "method": "Api|share_bottom" },
            dataType: 'json',
            success: function(res) {
                if (res.status == 1) {
                    let data = res.data;
                    let html = '';
                    data.download.forEach(item => {
                        html += `
                <li><a href="${item.url}">${item.type_name}</a></li>
                `;
                    })
                    $('.dlLists').html(html);
                    $('.icp_info').html(data.icp_info);
                    $('.other_msg').html(data.other_msg);
                }
            }
        })
    }
})